/*
 * 文件名：TransFormPreReqParamsModelToXML.java
 * 版权：Copyright by www.suyinchina.com
 * 描述：
 * 修改人：XLY
 * 修改时间：2015-1-16
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

package com.caiyouxi.pay.payment.weixin.utils;

import com.caiyouxi.pay.payment.weixin.model.PreReqParamsModel;

import java.lang.reflect.Field;


public class TransFormPreReqParamsModelToXML
{   
    /**
     * 将PreReqParamsModel转换为xml
     * Description: <br>
     * 
     * @param preReqParamsModel
     * @return 
     * @see
     */
    public static String generateXMLByPreReqParamsModel(PreReqParamsModel preReqParamsModel){
        StringBuffer xml = new StringBuffer("<xml>");
        Class<PreReqParamsModel> clazz = PreReqParamsModel.class;
        Field[] fields = clazz.getDeclaredFields();
        for(Field f:fields){
            f.setAccessible(true);
            Object obj;
            try
            {
                obj = f.get(preReqParamsModel);
                if(obj!=null){
                    xml.append("<"+f.getName()+">"+obj.toString()+"</"+f.getName()+">");
                }
            }
            catch (IllegalArgumentException e)
            {
                e.printStackTrace();
            }
            catch (IllegalAccessException e)
            {
                e.printStackTrace();
            }
        }
        xml.append("</xml>");
        return xml.toString();
    }
}
